﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Enterprise.Data.Doc;
using Enterprise.Model.Doc;
using System.Data;

namespace Enterprise.Service.Doc
{
    public class DocClassService
    {
        private readonly Doc_Class dal=new Doc_Class();
        public DocClassService()
		{}
		#region  BasicMethod
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(decimal CLASSID)
		{
			return dal.Exists(CLASSID);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(DocClassEntity model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(DocClassEntity model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(decimal CLASSID)
		{
			
			return dal.Delete(CLASSID);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string CLASSIDlist )
		{
			return dal.DeleteList(CLASSIDlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public DocClassEntity GetModel(decimal CLASSID)
		{
			
			return dal.GetModel(CLASSID);
		}

        ///// <summary>
        ///// 得到一个对象实体，从缓存中
        ///// </summary>
        //public DocClassEntity GetModelByCache(decimal CLASSID)
        //{					
        //    return null
        //}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<DocClassEntity> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<DocClassEntity> DataTableToList(DataTable dt)
		{
			List<DocClassEntity> modelList = new List<DocClassEntity>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				DocClassEntity model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = dal.DataRowToModel(dt.Rows[n]);
					if (model != null)
					{
						modelList.Add(model);
				}
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			return dal.GetRecordCount(strWhere);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return dal.GetListByPage( strWhere,  orderby,  startIndex,  endIndex);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  BasicMethod
		#region  ExtensionMethod

		
        /// <summary>
        /// 栏目是否有文章
        /// </summary>
        /// <param name="_cid"></param>
        /// <returns></returns>
        public bool hasArticle(decimal _cid)
        {
            return dal.HasArticle(_cid);
        }


        /// <summary>
        /// 是否允许发布
        /// </summary>
        /// <param name="dt">dt中所有qx=1的Classid为授权栏目</param>
        /// <param name="userid"></param>
        /// <returns></returns>
        public bool AllowPub(out DataTable dt, int userid)
        {
            return dal.AllowPub(out dt,userid);
        }

        
        /// <summary>
        /// 某个栏目是否允许发布
        /// </summary>
        /// <param name="classid"></param>
        /// <param name="userid"></param>
        /// <returns></returns>
        public bool AllowPubInClass(decimal classid,int userid)
        {
            return dal.AllowPubInClass(classid, userid);
        }

        #endregion  ExtensionMethod
    }
}
